home *** CD-ROM | disk | FTP | other *** search
- pascal Boolean GenericFilter();
- void ConvertFile (char *theFile, int EOLmode);
-
- #include "ctc.h"
-
- /* Globals, used across procedures */
- DialogPtr dPtr;
-
- /* from tickle.c */
- OSErr TickleParent( FSSpec *);
- OSErr MakeWDSpec( FSSpec *, short, ConstStr255Param );
-
-
- /*
- >> ChangeTypeCreator.c
- >> change the file type and creator of any file dropped onto this program.
- >> Prompts for the file type and creator, and changes all files dropped at
- >> the same time to the same type and creator.
- >>
- >> Written by Brian Bechtel, based on code by Juri Munkki
- >> Feel free to use the code in your programs.
- */
-
- void ReadFinderStuff(type, creator, EOLmode)
- long type;
- long creator;
- int EOLmode;
- {
- short message,count,i;
- AppFile thefile;
- FileParam block;
- FSSpec spec;
- Str255 oldName;
- short oldVol;
-
- CountAppFiles(&message,&count);
- if(message==1)
- { return;
- }
- else
- { for(i=1;i<=count;i++)
- { GetAppFiles(i,&thefile);
-
- block.ioCompletion=0;
- block.ioNamePtr=thefile.fName;
- block.ioVRefNum=thefile.vRefNum;
- block.ioFVersNum=thefile.versNum;
- block.ioFDirIndex=0;
-
- /*
- * modify the EOL characters in the file
- */
- if (EOLmode != IGNORE)
- {
- GetVol (oldName, &oldVol);
- SetVol (0, thefile.vRefNum);
- p2cstr(thefile.fName);
- ConvertFile ((char *) thefile.fName, EOLmode);
- c2pstr((char *) thefile.fName);
- SetVol (0, oldVol);
- }
- if (PBGetFInfo((ParmBlkPtr)&block,0) == noErr)
- {
- block.ioFlFndrInfo.fdType = type;
- block.ioFlFndrInfo.fdCreator = creator;
- PBSetFInfo((ParmBlkPtr)&block,0);
- MakeWDSpec(&spec, thefile.vRefNum, thefile.fName );
- TickleParent(&spec);
- }
- }
- }
- }
-
- /*
- ** I put this call in a separate procedure to emphasize the fact that I'm
- ** modifying a global variable, dPtr, with the side effect of putting a dialog
- ** on the screen. I don't want to display the dialog if we just double-click
- ** on the application, so I'm calling this routine at a wierd time.
- */
- DisplayDialog()
- {
- dPtr = GetNewDialog(128, nil, (WindowPtr) -1);
- }
-
- void PopRadioButton (int button)
- {
- Handle itemHandle;
- short itemType;
- Rect box;
- ControlHandle theControl;
- Point thePoint;
-
- GetDItem(dPtr, button, &itemType, &itemHandle, &box);
- thePoint.v = box.top;
- thePoint.h = box.left;
- FindControl (thePoint, dPtr, &theControl);
- SetCtlValue(theControl, false);
- }
-
- void PushRadioButton (int button)
- {
- Handle itemHandle;
- short itemType;
- Rect box;
- ControlHandle theControl;
- Point thePoint;
-
- PopRadioButton (DOS);
- PopRadioButton (IGNORE);
- PopRadioButton (MAC);
- PopRadioButton (UNIX);
- GetDItem(dPtr, button, &itemType, &itemHandle, &box);
- thePoint.v = box.top;
- thePoint.h = box.left;
- FindControl (thePoint, dPtr, &theControl);
- SetCtlValue(theControl, true);
- }
-
- /*
- ** Check to see if we were opened from the Finder by counting the passed in
- ** app files. If we were opened by the finder, set the default type and
- ** creator to the first file's type and creator. If not, we'll default to
- ** whatever is in our dialog box.
- */
- Boolean GetTypeCreatorEOL()
- {
- long type;
- long creator;
- short message;
- short count;
- AppFile thefile;
- FileParam block;
- short itemHit;
- Handle itemHandle;
- short itemType;
- Rect box;
- Str255 itemString;
-
- CountAppFiles(&message,&count);
- if(count==0)
- return(false);
- else
- { GetAppFiles(1,&thefile); /* get Type & Creator of 1st file. */
-
- block.ioCompletion=0;
- block.ioNamePtr=thefile.fName;
- block.ioVRefNum=thefile.vRefNum;
- block.ioFVersNum=thefile.versNum;
- block.ioFDirIndex=0;
-
- if (PBGetFInfo((ParmBlkPtr)&block,0) == noErr)
- {
- type = block.ioFlFndrInfo.fdType;
- creator = block.ioFlFndrInfo.fdCreator;
-
- DisplayDialog();
-
- itemString[0] = 4; /* establish artificial length */
- GetDItem(dPtr, TYPE, &itemType, &itemHandle, &box);
- BlockMove(&type, (Ptr)&itemString[1], 4);
- SetIText(itemHandle, itemString);
- GetDItem(dPtr, CREATOR, &itemType, &itemHandle, &box);
- BlockMove(&creator, (Ptr)&itemString[1], 4);
- SetIText(itemHandle, itemString);
- PopRadioButton (DOS);
- PushRadioButton (IGNORE);
- PopRadioButton (MAC);
- PopRadioButton (UNIX);
- return(true);
- }
- }
- return(false);
- }
-
- Boolean AskNewTypeCreatorEOL(type, creator, EOLmode)
- long *type;
- long *creator;
- int *EOLmode;
- {
- short itemHit;
- Handle itemHandle;
- short itemType;
- Rect box;
- Str255 itemString;
-
- SelIText(dPtr, CREATOR, 0, 4);
- do {
- ModalDialog(GenericFilter, &itemHit);
- switch (itemHit) {
- case DOS:
- case IGNORE:
- case MAC:
- case UNIX:
- PushRadioButton (*EOLmode = itemHit);
- break;
- }
- } while ((itemHit != OK) && (itemHit != CANCEL));
-
- if (itemHit == CANCEL)
- return (false);
- else {
- GetDItem(dPtr, TYPE, &itemType, &itemHandle, &box);
- GetIText(itemHandle, itemString);
- BlockMove((Ptr)&itemString[1], type, 4);
- GetDItem(dPtr, CREATOR, &itemType, &itemHandle, &box);
- GetIText(itemHandle, itemString);
- BlockMove((Ptr)&itemString[1], creator, 4);
- return (true);
- }
- }
-
- void HandleUpdates()
- {
- /* Used to handle window updates for windows other than modal dialogs.*/
- /* We don't have any, so return without doing anything.*/
- }
-
- void main()
- {
- long type;
- long creator;
- int EOLmode;
-
- InitGraf(&thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitCursor();
- InitDialogs(nil);
- if (GetTypeCreatorEOL())
- if (AskNewTypeCreatorEOL(&type, &creator, &EOLmode))
- ReadFinderStuff(type, creator, EOLmode);
- }
-